﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtUsername.Focus();
    }
   

    private void ShowPopUpMsg(string msg)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("alert('");
        sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
        sb.Append("');");
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
    }

    protected void btnLogin_Click1(object sender, EventArgs e)
    {
        string msg = "Login Fail!";
        ShopLaptopConnection conn = new ShopLaptopConnection();
        SysAdmin ad = conn.GetAdminByUserPass(txtUsername.Text, txtPassword.Text);
        if (ad != null)
        {
            Session["Admin"] = ad;
            Response.Redirect("Home.aspx");
        }
        else
        {
            ShowPopUpMsg(msg);
        }
    }
}
